import {GuiRequest} from "./GuiRequest";
import {GuiResponse} from "./GuiResponse";
import {SerializeBody, SerializeBodyHistory} from "./SerializeBody";
import {PlayerModel} from "../../frame/apiModel/adapterModel/model4/PlayerModel";



export interface Broadcast {
    startListen(controller: Controller);
    broadcast(request: BroadcastRequest): BroadcastResponse;
}
export interface BroadcastRequest {
    controllerNo: ControllerNo;
    broadcastType: BroadcastType;
    data: any;
}
export interface BroadcastResponse {
    controllerNo: number;
    status: BroadcastResponseStatus;
    data: any;
}
// status为none时代表没找到对应控制器
export enum BroadcastResponseStatus {
    none = 1,
    success,
    failed,
}
export enum BroadcastType {
    // 通用
    serialize = 1,

    // 各控制器独自
    recordKillUnitNum,
    applyAutoTask,
    caluGoodAttributes,
    caluAbilityAttributes,
    caluAchievementAttributes,
    initGoodAttrMap,
    changeUnit,
    resetUnit,
    addAchievement,
    copyAbilitys,
    getAbilityBiggestFamilyLevel,
    copyGoods,
    addStoreTask,
    checkToInitMonster,
    removeAchievement,
    getAttribute,
    getGoodsBag,
    getGoodsEquip,
    mapGoodsAddEffect,
    toApplyTask,
    updateGui,
    showUi,
    isInPets,
    isInSummon,
    addCaluTaskByUnit,
    addCaluTaskByPlayer,
    removeSkill,
    learnSkill,
    learnSkillByFamilyLv,
    removeSkillByFamilyLv,
    getAchPool,
    getAchByPlayer,
    clearSummoneByEffectId,
    getMaxDifficult,
    getOneDayCheck,
    getLastTime,
    addPet,
    resumePet,
    resumeHero,
    rewardIntegral,
    rewardFreeExp,

    checkHasPet,
    getAchNum,

    toWinStore,
    toFaildStore,
    getAchHistory,
    getHandBookUnit,
    achEndStore,
    initHandBook,

    showTextUi,

    createUnit,
    clearUnitByPlayer,
    useTransData,
    dropFun,
    deleteAbilityAttr,
    loadApp,
    reward,

    reflushCool,
    initAbilityAttr,
    clearUnitStore,
}
export enum ControllerNo {
    AbilityController = 1,
    AchievementController,
    DialogController,
    GoodController,
    GuiController,
    TaskController,
    TimerController,
    UnitController,
    StoreController,
}

export enum SpecialStoreKey {
    lockKey = 'lock'
}
export interface Controller {
    getControllerNo(): number;

    init(data?: any);

    notify(request: BroadcastRequest): BroadcastResponse;
    serialize(player: PlayerModel, serializeHistory: SerializeBodyHistory): SerializeBody;
    // getSerializeKey(player: PlayerModel): string[];
    loadByJson(json: SerializeBody, player: PlayerModel);
}

export enum GuiKeys {
    erro,
    root = 1,
    damageButton,
    damageButtonContent,
    damagePanelBody,
    damagePanel,
    damagePanelTitle,
    damagePanelHurts,
    damagePanelTitleText,
    damagePanelTitlePlayerType,
    damagePanelTitlePetType,
    damagePanelHurtItem,
    damagePanelHurtLine,
    damagePanelHurtText,
    damagePanelHurtValue,

    hideAchBar,
    hideAchBarItem,

    talentBarItemNum,

    achBar,
    achBarResumeItem,
    achBarItem,
    achBarItemNum,
    achInfoText,
    achInfo,

    infoPageCon2,
    infoPageCon,
    infoPage,
    InfoPageText,

    dialogPageCon,
    dialogPageBack,
    dialogPage,
    dialogPageText,
    dialogPageButtonCon,
    dialogPageOkButton,
    dialogPageCanelButton,

    handBookBar,
    handBookBarItem,
    handBookBarIconCon,
    handBookBarIcon,
    handBookBarNo,
    handBookBarText,
    handBookBarName,
    handBookBarNameLv,
    handBookBarLines,
    handBookBarLine,
    handBookBarLvButton,
    handBookBarExp,
    handBookBarInfoCon,
    handBookBarInfo,
    handBookBarInfoName,
    handBookBarInfoAttr,
    handBookBarInfoNameAttr,
    handBookBarInfoDes,
    handBookBarInfoTalentIcon,
    handBookBarInfoTalentDes,
    handBookBarInfoHandBookFun,


    equipBarCon,
    equipBarItem,

    goodsBarCon,
    goodsBarItem,
    goodsBarItemNum,
    goodsBarCloseButton,
    goodsBarButton,
    goodsBarContextMenuCon,
    goodsBarContextMenu,
    goodsBarContextMenuUseButton,
    goodsBarContextMenuDropButton,
    goodsBarContextMenuSellButton,
    goodsBarContextMenuWashButton,
    goodsBarContextMenuDecomposeButton,
    goodsBarContextMenuforgButton,

    combinationBar,
    combinationBarCon,
    combinationBarItem,
    combinationBarCurrentNum,
    combinationBarItemModel,
    combinationBarItemMember,
    combinationBarTextCon,
    combinationBarName,
    combinationBarItemMembers,

    combinationBarInfoCon,
    combinationBarInfo,
    combinationBarInfoTitle,
    combinationBarInfoDes,
    combinationBarInfoMember,
    combinationBarInfoText,

    attrShowBar,
    attrShowBarNormalAttrContent,
    attrShowBarNormalAttrText,
    attrShowBarNormalAttrValue,
    petBarAttrContent,

    attrBar,
    attrBarCon,
    attrBarNormal,
    attrBarNormalTitle,
    attrBarNormalAttrContent,
    attrBarSpecial,
    attrBarSpecialTitle,
    attrBarSpecialAttrContent,
    attrBarAttack,
    attrBarAttackTitle,
    attrBarAttackAttrContent,
    attrBarLive,
    attrBarLiveTitle,
    attrBarLiveAttrContent,

    pageContentAdmin,
    pageContentAch,
    pageContentTalent,
    pageContentUnitShop,
    pageContentApp,
    pageContentMall,
    pageContentHideAch,
    pageContentHandBook,
    pageContent,
    pageContentDesText,
    pageContentSideBar,
    pageContentSideBarUp,
    pageContentSideBarUpItem,
    pageContentSideBarDown,
    pageContentSideBarDownItem,
    pageContentSideBarItem,
    pageContentContent,
    pageContentFoot,
    pageContentToRight,
    pageContentPageNum,
    pageContentToLeft,
    pageContentClose,

    buttonEnter,
    buttonEnterContent,
    buttonEnterBag,
    buttonEnterAch,
    buttonEnterTalent,
    buttonEnterAttr,
    buttonEnterHandBook,
    buttonEnterAppear,
    buttonEnterMall,
    buttonEnterHideAch,

    appearBar,
    appearInfoCon,
    appearInfo,
    appearInfoText,

    chooseHeroBarCon,
    chooseHeroBar,
    chooseHeroBarContent,
    chooseHeroAllButton,
    chooseHeroEnter,
    chooseHeroIcon,

    chooseHeroInfoCon,
    chooseHeroInfo,
    chooseHeroInfoIcon,
    chooseHeroInfoNameAttr,
    chooseHeroInfoName,
    chooseHeroInfoAttr,
    chooseHeroInfoDescribe,
    // chooseHeroInfoTalent,
    chooseHeroInfoTalentIcon,
    chooseHeroInfoTalentDes,
    chooseHeroInfoLocStr,

    threeChooseOneAchBar,
    threeChooseOneAchBarItem,
    threeChooseOneAchBarItemLv,
    threeChooseOneAchBarItemIcon,
    threeChooseOneAchBarItemName,
    threeChooseOneAchBarItemDes,
    threeChooseOneAchBarItemEventFlog,

    threeChooseOneGoodBar,
    threeChooseOneGoodBarInfoPage,
    threeChooseOneGoodBarItem,

    threeChooseOneContent,

    textGui,
    textGuiContent,
    textGuiItem,

    wheelGui,
    wheelGuiContent,
    wheelGuiItem,

    taskButtonCon,
    taskButtonTitle,
    taskButton,
    taskBar,
    taskBarCon,
    taskBarItem,
    taskBarItemCloseButton,
    taskBarItemIcon,
    taskBarItemName,
    taskBarItemContent,
    taskBarItemModel,

    talentBar,
    talentInfoCon,
    talentBarCon,
    talentBarItem,
    talentBarLv,

    petBar,
    petBarLeft,
    petBarRight,
    petBarLife,
    petBarLifeText,
    petBarMagic,
    petBarMagicText,
    petBarAttr,
    petBarCon,
    petBarTitle,
    petBarName,
    petBarLv,
    petBarItems,
    petBarModel,
    petBarButtons,
    petBarCall,
    petBarRelease,
    petBarItem,
    petBarFight,
    petBarIcon,
    petBarIconFight,
    petBarIconResume,
    petBarIconLv,
    petBarIconModel,


    goodBar,
    equipBar,
    goodInfoPage,
    goodInfoPageText,

    resumeBar,
    resumeBarContent,
    resumeBarText,
    resumeBarButtonContent,
    resumeBarButtonEnter,
    resumeBarButtonCanel,

    bossLifeBarContent,
    bossLifeBar,
    bossLifePercentBar,

    petLifePercentBar,
    petMagicPercentBar,


    percentBar,
    percentBarLine,
    percentBarText,

    chooseDiffBar,
    chooseDiffBarContent,
    chooseDiffBarContentLeft,
    chooseDiffBarContentRight,
    chooseDiffBarModeList,
    chooseDiffBarModeItem,
    chooseDiffBarModeItemText,
    chooseDiffBarDiffList,
    chooseDiffBarDiffItem,
    chooseDiffBarDiffItemText,

    chooseArchiveBarCon,
    chooseArchiveBar,
    chooseArchiveBarBoard,
    chooseArchiveBarIcon,
    chooseArchiveBarText,
    chooseArchiveBarButton,
    chooseArchiveBarItem,

    uiShopCon,
    uiShopInfo,

    integralMallBar,
    integralMallInfoCon,
    integralMallItem,
    integralText,

    buffBarContent,
    buffBar,
    buffsContent,
    buffsText,
    buffs,
    buffItem,

    buffNameText,
    buffLvText,
    buffLv,
    buffLvLine,
    buffAttrText,
    buffAttrAttackText,
    buffAttrAttackTextContent,
    buffAttrDefenseText,
    buffAttrDefenseTextContent,
    buffAttrSpeedText,
    buffAttrSpeedTextContent,

    adminBarCon,
    adminBar,
    adminBarItem,
    adminBarInfo,

    multiBarCon,
    multiBar,
    multiBarRowsItem,
    multiBarRowItem,
    multiBarButton,

    topBarCon,
    topBar,
    topBarText,
    topBarText1,
    topBarText2,
    topBarCoinIcon,
    topBarCoinText,
    topBarWoodIcon,
    topBarWoodText,
    topBarKillIcon,
    topBarKillText,

    smallAttrBarCon,
    smallAttrBar,
    smallAttrBarToast,
    smallAttrBarTexts,
    smallAttrBarText,

    heroAvatarBarName,
    heroAvatarBarCon,
    heroAvatarBar,
    heroAvatarBarExpCon,
    heroAvatarBarExp,
    heroAvatarBarLifeCon,
    heroAvatarBarLife,
    heroAvatarBarManaCon,
    heroAvatarBarMana,
    heroAvatarBarBack,
    heroAvatarBarAvatar,
    heroAvatarBarAvatarMask,
    heroAvatarBarAvatarText,
    heroAvatarBarLv,

    skillBarCon,
    skillBar,
    skillBarItem,
    skillBarFrame,
    skillBarImage,
    skillBarMask,
    skillBarMaskKey,
    skillBarMaskNum,
    skillBarInfo,

    itemBarCon,
    itemBar,
    itemBarItem,
    itemBarTargetItem,
    itemBarItemBack,
    itemBarFrame,
    itemBarItemNum,
    itemBarImage,
    itemBarMask,
    itemBarMaskKey,
    itemBarInfo,

    itemShopBarCon,
    itemShopBarInfo,
    itemShopBarItem,
    itemShopBarItemNum,
    itemShopBarItemMask,
    itemShopBarItemModel,

    chatBarCon,
    chatBar,
    chatBarItem,

    lightButton,
    sideButtons,
}
export enum GuiId {
    buttonEnter = 'buttonEnter',
    textGuiBar = 'textGuiBar',
    toastWheelBar = 'toastWheelBar',
    damageButton = 'damageButton',
    taskButton = 'taskButton',
    equipBar = 'equipBar',
    goodsBar = 'goodsBar',
    chooseHeroBar = 'chooseHeroBar',
    chooseAchBar = 'chooseAchBar',
    chooseItemBar = 'chooseItemBar',
    combinationBar = 'combinationBar',
    petBar = 'petBar',
    resumeBar = 'resumeBar',
    bossLifeBar = 'bossLifeBar',
    chooseDiffBar = 'chooseDiffBar',
    chooseArchiveBar = 'chooseArchiveBar',

    achBar = 'achBar',
    hideAchBar = 'hideAchBar',
    talentBar = 'talentBar',
    attrBar = 'attrBar',
    handBookBar = 'handBookBar',
    appBar = 'appBar',
    integralMallBar = 'integralMallBar',
    buffBar = 'buffBar',
    adminBar = 'adminBar',

    multiBoradBar = 'multiBoradBar',
    smallAttrBar = 'smallAttrBar',
    avatarBar = 'avatarBar',
    skillBar = 'skillBar',
    itemBar = 'itemBar',
    topBar = 'topBar',
    unitShopBar = 'unitShopBar',
    chatBar = 'chatBar',
}

export interface UISkillObj {
    guiId: GuiId,
    skillId: string
}

export enum GuiLevel {
    low,
    high,
}
export enum GuiType {
    FRAME = 'FRAME' ,
    BACKDROP = 'BACKDROP' ,
    TEXT = 'TEXT' ,
    BUTTON = 'BUTTON' ,
    GLUEBUTTON = 'GLUEBUTTON' ,
    GLUETEXTBUTTON = 'GLUETEXTBUTTON' ,
    EDITBOX = 'EDITBOX' ,
    SLIDER = 'SLIDER' ,
    MODEL = 'MODEL',
    SPRITE = 'SPRITE',
}
export interface GuiEventObj {
    [key: string]: () => void;
}
// ---------------------------------------------------------------------------------------------------------------------------------------------------------------
export class ControllerOpt {
    id: string | undefined;
    callBack: (self: ControllerOpt) => void;
    self: this;
    constructor(id: string | undefined, callBack: (self: ControllerOpt) => void = () => {}) {
        this.id = id;
        this.callBack = callBack;
        this.self = this;
    }
}
export class DialogControllerOpt extends ControllerOpt {
}
export class TimeControllerOpt extends ControllerOpt {
    periodic: number
    constructor(id: string | undefined, callBack: (self: ControllerOpt) => void = () => {}, periodic: number) {
        super(id, callBack);
        this.periodic = periodic;
    }
}
export class GuiControllerOpt extends ControllerOpt {
    request: GuiRequest;
    response: GuiResponse;
    constructor(id: string | undefined, request: GuiRequest) {
        super(id, undefined);
        this.request = request;
    }
}